{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  \n",
    "+ 学号"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你要的全拿走 剩下的我承受 留下我们的狗 别管有没有用 我怕它以后没人宠 哪怕它不懂我的痛 我不必再为你强求\n",
      "一年两年三年 已经沉默寡言 好聚好散听着也楚楚可怜\n",
      "看见的都在消遣 特价卖出不管它贵贱 一个接着一个\n",
      "一排接着一排的清点在消灭 关了门我们两不相欠 \n",
      "开头都是你在问 结果总是我在等 说话留着分寸 气氛却不见加温 爱没有了库存\n",
      "你说的这么认真 显得我存心敷衍 这些套路的情节 苍白的上了台面\n",
      "是不是分开一定要留恋 才觉得不那么随便\n",
      "你说的这么认真\n",
      "显得我存心敷衍 这些套路的情节 苍白的上了台面\n",
      "是不是分开一定要留恋 才觉得不那么随便\n",
      "开头都是你在问 结果总是我在等 说话留着分寸 气氛却不见加温 爱没有了库存\n",
      "你说的这么认真 显得我存心敷衍 这些套路的情节 苍白的上了台面\n",
      "是不是分开一定要留恋 才觉得不那么随便\n",
      "开头都是你在问 结果总是我在等 说话留着分寸 气氛却不见加温 爱没有了库存\n",
      "你说的这么认真 显得我存心敷衍 这些套路的情节 苍白的上了台面\n",
      "是不是分开一定要留恋 才觉得不那么随便\n"
     ]
    }
   ],
   "source": [
    "def chrous_song(song):\n",
    "    print(\"开头都是你在问 结果总是我在等 说话留着分寸 气氛却不见加温 爱没有了库存\\n你说的这么认真 显得我存心敷衍 这些套路的情节 苍白的上了台面\\n是不是分开一定要留恋 才觉得不那么随便\")\n",
    "print(\"你要的全拿走 剩下的我承受 留下我们的狗 别管有没有用 我怕它以后没人宠 哪怕它不懂我的痛 我不必再为你强求\\n一年两年三年 已经沉默寡言 好聚好散听着也楚楚可怜\\n看见的都在消遣 特价卖出不管它贵贱 一个接着一个\\n一排接着一排的清点在消灭 关了门我们两不相欠 \")\n",
    "chrous_song(\"你要的全拿走\")\n",
    "print(\"你说的这么认真\\n显得我存心敷衍 这些套路的情节 苍白的上了台面\\n是不是分开一定要留恋 才觉得不那么随便\")\n",
    "chrous_song(\"你要的全拿走\")\n",
    "chrous_song(\"你要的全拿走\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mean=4.75\n",
      "variance=5.02\n",
      "n=12\n",
      "mean=50.42\n",
      "variance=482.08\n",
      "n=12\n"
     ]
    }
   ],
   "source": [
    "def caculation(*args):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for value in args:\n",
    "        a=a+value            \n",
    "        n+=1\n",
    "    print('mean=%.2f'%(a/n))\n",
    "    for value in args:\n",
    "        b=b+(value-a/n)**2 \n",
    "    print('variance=%.2f'%(b/n))\n",
    "    print('n=%d'%n)\n",
    "\n",
    "caculation(5,5,7,0,2,4,3,7,8,5,7,4)\n",
    "caculation(25,57,45,12,87,65,54,47,84,62,24,43)\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "choose  variance,input 1\n",
      "choose standard deviation,input 2\n",
      "1\n",
      "\n",
      "\n",
      "mean=4.75\n",
      "standard deviation=2.24\n",
      "n=12\n",
      "\n",
      "choose  variance,input 1\n",
      "choose standard deviation,input 2\n",
      "2\n",
      "\n",
      "\n",
      "mean=50.42\n",
      "variance=482.08\n",
      "n=12\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import numbers\n",
    "def caculation(*args):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for value in args:\n",
    "        a=a+value\n",
    "        n+=1\n",
    "    for value in args:\n",
    "        b=b+(value-a/n)**2   \n",
    "    print('choose  variance,input 1') \n",
    "    print('choose standard deviation,input 2')\n",
    "    q=int(input())\n",
    "    print('\\n\\nmean=%.2f'%(a/n))\n",
    "    if q==2:\n",
    "        print('variance=%.2f'%(b/n))       \n",
    "    else:\n",
    "        print('standard deviation=%.2f'%math.sqrt(b/n))  \n",
    "    print('n=%d\\n'%n)\n",
    "    \n",
    "caculation(5,5,7,0,2,4,3,7,8,5,7,4)\n",
    "caculation(25,57,45,12,87,65,54,47,84,62,24,43)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "choose  variance,input 1\n",
      "choose standard deviation,input 2\n",
      "2\n",
      "if you want to input Standard error、max and min,you can choose 1\n",
      "2\n",
      "\n",
      "\n",
      "mean=4.75\n",
      "variance=5.02\n",
      "standard error=0.19\n",
      "max=8\n",
      "min=0\n",
      "n=12\n",
      "\n",
      "choose  variance,input 1\n",
      "choose standard deviation,input 2\n",
      "1\n",
      "if you want to input Standard error、max and min,you can choose 1\n",
      "1\n",
      "\n",
      "\n",
      "mean=50.42\n",
      "standard deviation=21.96\n",
      "n=12\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import numbers\n",
    "def caculation(*args):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for value in args:\n",
    "        a=a+value\n",
    "        n+=1\n",
    "    for value in args:\n",
    "        b=b+(value-a/n)**2 \n",
    "    print('choose  variance,input 1')  \n",
    "    print('choose standard deviation,input 2')\n",
    "    q=int(input())\n",
    "    print('if you want to input Standard error、max and min,you can choose 1')  \n",
    "    w=int(input())\n",
    "    print('\\n\\nmean=%.2f'%(a/n))\n",
    "    if q==2:\n",
    "        print('variance=%.2f'%(b/n))  \n",
    "    else:\n",
    "        print('standard deviation=%.2f'%math.sqrt(b/n)) \n",
    "    if w==2:\n",
    "        print('standard error=%.2f'%math.sqrt(b/(n**3)))  \n",
    "        print('max=%d'%max(args))        \n",
    "        print('min=%d'%min(args))         \n",
    "    print('n=%d\\n'%n)\n",
    "\n",
    "caculation(5,5,7,0,2,4,3,7,8,5,7,4)\n",
    "caculation(25,57,45,12,87,65,54,47,84,62,24,43)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
